package com.guigu.service.impl.stock;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.mapper.stock.SPayDetailsMapper;
import com.guigu.pojo.stock.SPayDetails;
import com.guigu.service.stock.SPayDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Mr.Zhang
 * @since 2024-12-06
 */
@Service
public class SPayDetailsServiceImpl extends ServiceImpl<SPayDetailsMapper, SPayDetails> implements SPayDetailsService {

    @Autowired
    private SPayDetailsMapper sPayDetailsMapper;

    @Override
    public ArrayList<SPayDetails> selectArrByParentId(Integer parentId) {
        QueryWrapper<SPayDetails> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("PARENT_ID", parentId);
        ArrayList<SPayDetails> sPayDetails = (ArrayList<SPayDetails>)sPayDetailsMapper.selectList(queryWrapper);
        return sPayDetails;
    }

    @Override
    public SPayDetails selectById(Integer id) {
        SPayDetails sPayDetails = sPayDetailsMapper.selectById(id);
        return sPayDetails;
    }

    @Override
    public boolean updateSpayDetails(SPayDetails spayDetails) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("PARENT_ID",spayDetails.getParentId());
        queryWrapper.eq("PRODUCT_ID",spayDetails.getProductId());
        int rows = sPayDetailsMapper.update(spayDetails, queryWrapper);
        return rows>0;
    }

    @Override
    public boolean selectParentId(Integer parentId, String payTag) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("PARENT_ID",parentId);
        queryWrapper.eq("PAY_TAG",payTag);
        ArrayList<SPayDetails> list = (ArrayList<SPayDetails>)sPayDetailsMapper.selectList(queryWrapper);
        if(list.size()>0){
            return true;
        }else{
            return false;
        }
    }


}
